<%-- 
    Document   : list
    Created on : 2014/8/19, 下午 02:19:29
    Author     : LENOVO
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/javadb","root","root");
    Statement st = con.createStatement();
    String sql ="select id , username , tel , birthday from person";
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <style>
            a{text-decoration:none}
        </style>
    </head>
    <body>
        <table border="1">
            
        <%
            ResultSet rs = st.executeQuery(sql);
        %>
            <tr align="center">
                <td>編號</td>
                <td>姓名</td>
                <td>電話</td>
                <td>生日</td>
                <td>修改</td>
                <td></td>
            </tr>    
        <%
            while(rs.next()){
                String id = rs.getString("id");
                String username = rs.getString("username");
                String tel = rs.getString("tel");
                String birthday = rs.getString("birthday");
        %>
            <tr  align="center">
                <td> <%=id %> </td>
                <td> <%= username %> </td>
                <td> <%= tel %> </td>
                <td> <%= birthday %> </td>
                <td> <a href="Upload1.jsp?id=<%=id %>">◆</a> </td>
                <td> <input type="button" value="刪除" onclick="doDelete('<%= id %>')"> </td>

            </tr>
        <%
            }
            rs.close();
            st.close();
            con.close();
        %>
        </table>
        
        <script>
            function doDelete(x)
            {
                if(confirm('是否刪除'))
                {
                    //alert('x:' + x);
                    document.getElementById('id').value=x;
                    document.getElementById('form1').submit();
                }    
            }
        </script>
        
        <form action="Delete.jsp" id="form1">
            <input type="hidden" name="id" id="id" value="">
        </form>
    </body>
</html>
